#!/bin/bash

app_name="hadoop "
app_home='/opt/app/hadoop'
filter_str='echo `jps|egrep "NameNode|ResourceManager|SecondaryNameNode|DataNode|NodeManager"`'
function print()
{
        echo " │"
        echo " ├$app_name $1 节点"
        echo " └───────────────"
}
function start()
{
	echo ""
	echo "#$app_name 集群启动中..."
	ssh bigdata3 $app_home'/sbin/start-dfs.sh'
	ssh bigdata3 $app_home'/sbin/start-yarn.sh'
	print 3
}
function stop()
{
	echo ""
	echo "#$app_name 集群关闭中..."
        ssh bigdata3 $app_home'/sbin/stop-dfs.sh'
        ssh bigdata3 $app_home'/sbin/stop-yarn.sh'
	print 3
}
function status()
{
	echo ""
	echo "#$app_name 集群状态..."
	ssh bigdata1 $filter_str
	print 1
	ssh bigdata2 $filter_str
	print 2
	ssh bigdata3 $filter_str
	print 3
}
arg=$1
if [ "$arg" = "" ];then
	echo "请传入[start|stop|restart|status]参数,不传默认为[status]"
	arg="status"
	
fi
if [ "$arg" = "start" ];then
	start
	status
elif [ "$arg" = "stop" ];then
	stop
	status
elif [ "$arg" = "restart" ];then
	stop
	start
	status
elif [ "$arg" = "status" ];then
	status
else
	echo "请传入start|stop|restart|status参数"
fi
